package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.HomeService;
import com.atguigu.spzx.model.dto.chat.BussnessDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.sell.SellVo;
import com.atguigu.spzx.utils.AuthContextUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.spzx.model.vo.chat.bussnessVo;
import com.atguigu.spzx.model.vo.address.addressVo;
import com.atguigu.spzx.model.dto.order.createOrderDto;

import java.util.List;

@Tag(name = "首页")
@RestController
@RequestMapping(value = "/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @GetMapping(value = "/getall")
    public Result<SellVo> GetAllSell(){
        List<SellVo> list = homeService.GetAllsell();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping(value = "/selldetails/{id}")
    public Result<SellVo> GetSellById(@PathVariable Integer id){
        SellVo sellVo = homeService.GetSellById(id);
        return Result.build(sellVo,ResultCodeEnum.SUCCESS);
    }

    @GetMapping(value = "/selldetails/bussnessavatar/{bussnessName}")
    public Result<bussnessVo> GetAvatar(@PathVariable String bussnessName){
        bussnessVo bussnessVo = homeService.GetAvatar(bussnessName);
        return Result.build(bussnessVo,ResultCodeEnum.SUCCESS);
    }

    //咨询商家
    @PutMapping(value = "/selldetails/GoToChat")
    public Result CreateChat(@RequestBody BussnessDto bussnessDto){
        homeService.CreateChat(bussnessDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //获取当前用户的所有地址信息
    @GetMapping(value = "/selldetails/getuseraddress")
    public Result<addressVo> GetUserAddress(){
        SysUser sysUser = AuthContextUtil.get();
        Long id = sysUser.getId();
        List<addressVo> address = homeService.GetUserAddress(id);
        return Result.build(address,ResultCodeEnum.SUCCESS);
    }

    @PostMapping(value = "/selldetails/buysell/createorder")
    public Result CreateOrder(@RequestBody createOrderDto createOrderDto){
        homeService.CreateOrder(createOrderDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
